package com.mingmen.canting.personal;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mingmen.canting.R;
import com.mingmen.canting.activity.BohuiYuanyinActivity;
import com.mingmen.canting.activity.YiShenHeActivity;
import com.mingmen.canting.adapter.PersonalJuJueListAdapter;
import com.mingmen.canting.definerecycleview.SwipeRecyclerView;
import com.mingmen.canting.util.DividerItemDecoration;
import com.mingmen.canting.util.SharePreferenceUtil;
import com.mingmen.canting.zhenban.ZhenBanDingDanActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

@SuppressLint("ValidFragment")
public class PersonalJuJuefragment extends Fragment implements PersonalJuJueListAdapter.OnItemClickListener {

    @BindView(R.id.recyclerview)
    SwipeRecyclerView mRecyclerview;

    Unbinder unbinder;
    private String mTitle;

    private PersonalJuJueListAdapter bohuiListAdapter = null;
    private LinearLayoutManager mLinearLayoutManager;


    public static PersonalJuJuefragment getInstance(String title) {
        PersonalJuJuefragment sf = new PersonalJuJuefragment();
        sf.mTitle = title;
        return sf;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    String token;
    List<String> dataBeanList = new ArrayList<>();
    @BindView(R.id.frame_layout)
    FrameLayout frame_layout;
    @BindView(R.id.layout_nodata)
    LinearLayout layout_nodata;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_personaljujue, null);
        TextView card_title_tv = (TextView) v.findViewById(R.id.card_title_tv);
        card_title_tv.setText(mTitle);
        token = (String) SharePreferenceUtil.get(getActivity(), "token", "");
        unbinder = ButterKnife.bind(this, v);
        for (int i = 0; i < 10; i++) {
            dataBeanList.add("ITem" + i);
        }

        bohuiListAdapter = new PersonalJuJueListAdapter(getActivity(), dataBeanList);
        mLinearLayoutManager = new LinearLayoutManager(getActivity());
        mRecyclerview.setLayoutManager(mLinearLayoutManager);
        bohuiListAdapter.setOnItemClickListener(this);
        DividerItemDecoration itemDecorationHeader = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST);
        itemDecorationHeader.setDividerDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.divider_main_bg_height_1));
        mRecyclerview.addItemDecoration(itemDecorationHeader);

        mRecyclerview.setAdapter(bohuiListAdapter);
        bohuiListAdapter.setDataList(dataBeanList);


        return v;
    }






    @OnClick({R.id.recyclerview})
    public void onViewClicked(View view) {
        switch (view.getId()) {

            case R.id.recyclerview:
                break;


            case R.id.btn_digndan:
                startActivity(new Intent(getActivity(), ZhenBanDingDanActivity.class));
//                startActivity(new Intent(getActivity(), DingDanActivity.class));
                break;
        }
    }

    @Override
    public void onItemClickListener(View view, int pos, PersonalJuJueListAdapter.ViewName viewName, List<String> myLiveLists) {
        Intent intent;
        switch (view.getId()) {

            case R.id.btn_zhuijia:


                break;
            case R.id.layout_bohui:

                intent = new Intent(getActivity(), BohuiYuanyinActivity.class);

                startActivity(intent);

                break;
            default:

                Intent intent2 = new Intent(getActivity(), YiShenHeActivity.class);

//                applyTime
                intent2.putExtra("position", pos+"");

                startActivity(intent2);
                break;
        }
    }
}